﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PLCS.App.OrderTask.Views.Order;

/// <summary>
/// OrderView.xaml 的交互逻辑
/// </summary>
public partial class OrderView : UserControl
{
    public OrderView()
    {
        InitializeComponent();
    }

    #region 折叠行

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Button bt = sender as Button;
        if (bt.Tag.ToString() == "1")
        {
            DataGridRow row = FindVisualParent<DataGridRow>(sender as Button);
            row.DetailsVisibility = System.Windows.Visibility.Collapsed;
            bt.Tag = "0";
        }
        else
        {
            DataGridRow row = FindVisualParent<DataGridRow>(sender as Button);
            row.DetailsVisibility = System.Windows.Visibility.Visible;
            bt.Tag = "1";
        }
    }

    #endregion 折叠行

    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="child"></param>
    /// <returns></returns>
    public T FindVisualParent<T>(DependencyObject child) where T : DependencyObject
    {
        DependencyObject parentObject = VisualTreeHelper.GetParent(child);
        if (parentObject == null) return null;
        T parent = parentObject as T;
        if (parent != null)
            return parent;
        else
            return FindVisualParent<T>(parentObject);
    }
}